from app.core.exception import ApiException
from app.entity.blackToken import BlackToken


class BlackTokenService:

    @staticmethod
    def checkToken(token):
        if len(token)==0:
            raise ApiException("token不存在")
        cnt=BlackToken().query().where(BlackToken.token==token).count()
        if cnt>0:
            raise ApiException("token已被禁用")
        
    @staticmethod
    def addBlackToken(token):
        if len(token)==0:
            raise ApiException("token不存在")
        blackToken=BlackToken()
        blackToken.token=token
        blackToken.save()
        blackToken.commit()